﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;
using System.Text;

namespace MVCnExt.Web.UI.Ext
{
     /// <summary>
    /// The default SelectionModel used by Ext.grid.GridPanel. It supports multiple
    /// selections and keyboard selection/navigation. The objects stored as selections
    /// and returned by getSelected, and getSelections are the Records which provide
    /// the data for the selected rows.
    /// </summary>
    [Description("The default SelectionModel used by Ext.grid.Grid. It supports multiple selections and keyboard selection/navigation. The objects stored as selections and returned by getSelected, and getSelections are the Records which provide the data for the selected rows.")]
    public class ExtRowSelectionModel : ExtConfig
    {
        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            if (list.Count == 0)
                list.Add(new ExtScriptControlDescriptor("Ext.grid.RowSelectionModel", "ctl00"));

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.grid.RowSelectionModel";

            String[] properties = new String[]{
                "singleSelect", "moveEditorOnEnter"     
            };

            Type component = typeof(ExtRowSelectionModel);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);

                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtRowSelectionModel.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }

            return list;
        }
        

        /// <summary>
        /// True to allow selection of only one row at a time (defaults to false)
        /// </summary>
        [Description("True to allow selection of only one row at a time (defaults to false).")]
        public Boolean? singleSelect { get; set; }

        /// <summary>
        /// False to turn off moving the editor to the next cell when the enter key is pressed
        /// </summary>
        [DefaultValue(true)]
        [Description("False to turn off moving the editor to the next cell when the enter key is pressed.")]
        public Boolean? moveEditorOnEnter { get; set; }

    }
}
